<template>
	<view style="padding-top:3px;">
		<view v-if="editEnable" class="model-border" style="display: flex;align-items: center;">
			<view class="title"></view>
			<text class="icon-title">信息录入</text>
		</view>
		<view class="content">
			<view class="content_text">
				<text>队伍名称</text>
				<text style="color: red;">*</text>
			</view>
			<u-input class="content-input" v-model="form.name" :clearable="false" placeholder="请输入队伍名称" type="number" />
		</view>
		<view class="content">
			<view class="content_text">
				<text>队伍人数</text>
				<text style="color: red;">*</text>
			</view>
			<u-input class="content-input" v-model="form.num" :clearable="false" placeholder="请输入队伍人数" type="number" />
		</view>
		<view class="content">
			<view class="content_text">
				<text>成立时间</text>
				<text style="color: red;">*</text>
			</view>
			<u-input class="content-input" v-model="form.found_date" :clearable="false" 
				 @click="showFoundDate = true" placeholder="请输入成立时间" type="number" />
			<view class='right'>
				<image src='../../static/right.png'></image>
			</view>
		</view>
		<view class="content_remack">
			<view class="content_text_remack">
				<text>备注</text>
			</view>
			<textarea v-model="form.remark" class="content_area"/>
		</view>
		<view v-if="editEnable" class="open_invoice" @click="submit">
			<text>提交</text>
		</view>
		<u-picker mode="time" v-model="showFoundDate" @confirm="selectTime"></u-picker>
		<u-top-tips ref="uTips"></u-top-tips>
	</view>
</template>

<script>
	import common from '../../common/common.js'
	export default {
		data() {
			return {
				dictValue: common.dictValue,
				createEnable: false,
				editEnable: true,
				showFoundDate: false,
				showSelect: false,
				showHolds: false,
				showSex: false,
				form: {},
				display:{},
			}
		},
		onLoad(options) {
			console.log(options);
			this.enterprise_id = options.enterprise_id;
			if(options && options.item){
				options.item = decodeURIComponent(options.item);
				this.form.enterprise_id = options.enterprise_id;
			}
			if(options.item=="0"){
				this.createEnable = true;
			}
			if(options && options.item && options.item!="0"){				
				this.editEnable = false;
				this.form = JSON.parse(options.item);
				//this.display = this.getValueLabels(common.dictValue, this.form);
			}
			if(options.t == "edit"){
				this.editEnable = true;
			}
			console.log(this.form);
		},
		methods: {
			getValueLabels(dictValue, values) {
				return {
					"seasonLabel": dictValue.season[values.season],
					"statusLabel": dictValue.businessstatus[values.status],
				};
			},
			selectTime(e) {
				this.form.found_date = e.year + '-' + e.month + '-' + e.day
				console.log(e)
			},
			selectCommunity(e) {
				this.form.community = e[0].label
			},
			selectHolds(e) {
				this.form.holds = e[0].label
			},
			submit() {
				var that = this;
				if(this.checkForm()){
					var cookie =  uni.getStorageSync('cookie');
					uni.showLoading({"title":"数据提交中..."});
					//新增API地址
					var url = this.$common.baseUrl + 'api/data/editCompanySafe';
					if(that.createEnable){
						//修改API地址
						url = this.$common.baseUrl + 'api/data/addCompanySafe';
					}
					uni.request({
						url: url,
						header: {'content-type': 'application/x-www-form-urlencoded','cookie':cookie},					
						data: that.form,
						method: 'POST',
						success: res => {
							uni.hideLoading();
							if (res.data.code == 1) {
								uni.showToast({title: '操作成功',duration: 2000})
								uni.navigateTo({
									url:'/pages/cart/detalis?id='+that.enterprise_id
								})
							}
						},
						fail: err => {uni.hideLoading();}
					})					
				}
			},
			checkForm(){
				if (!this.form.name) {
					this.$refs.uTips.show({title: '请输入队伍名称',type: 'error',duration: '2000'})
					return false;
				}
				if (!this.form.num) {
					this.$refs.uTips.show({title: '请输入队伍人数',type: 'error',duration: '2000'})
					return false;
				}
				return true;
			},
		}
	}
</script>

<style scoped>
	.title {
		height: 40rpx;
		width: 10rpx;
		background-color: #68B92E;
		margin: 20rpx 0 20rpx 20rpx;
	}

	.icon-title {
		display: block;
		line-height: 100rpx;
		padding-left: 10rpx;
		font-weight: bold;
	}

	.content {
		width: 95%;
		height: 80rpx;
		margin: 0 auto;
		background-color: #F7F7F7;
		border-radius: 15rpx;
		display: flex;
		align-items: center;
		margin-bottom: 10rpx;
	}

	.content_remack {
		width: 95%;
		height: 280rpx;
		margin: 0 auto;
		background-color: #F7F7F7;
		border-radius: 15rpx;
		margin-bottom: 10rpx;
	}

	.content_text {
		font-size: 26rpx;
		letter-spacing: 2rpx;
		margin-left: 30rpx;
		width: 200rpx;
		
	}
	.content_text_remack{
		font-size: 26rpx;
		letter-spacing: 2rpx;
		margin-left: 30rpx;
		height: 80rpx;
		display: flex;
		align-items: center;
	}
	.content_area{
		width: 95%;
		margin: 0 auto;
		height: 200rpx;
	}
	.right {
		width: 50rpx;
	}

	.right image {
		width: 30rpx;
		height: 30rpx;
	}

	>>>.u-input {
		border: none !important;
	}

	.content-input {
		flex: 1 !important;
	}

	.open_invoice {
		width: 400rpx;
		height: 90rpx;
		background-color: #68B92E;
		text-align: center;
		border-radius: 15rpx;
		margin: 20rpx auto;
		display: flex;
		justify-content: center;
		align-items: center;
	}

	.open_invoice text {
		font-size: 25rpx;
		font-family: Source Han Serif CN;
		font-weight: 500;
		color: #FFFFFF;
		line-height: 20rpx;
		display: block;
	}
</style>
